package javaStu.Lambda;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * Lambda表达式的测试
 * @author: leiwenkang02@meituan.com
 * @date: 2019/4/30
 * @time: 11:15
 */

public class Test01 {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<>();

        Person person1 = new Person();
        person1.setAge(10);

        Person person2 = new Person();
        person2.setAge(28);

        persons.add(person1);
        persons.add(person2);

        long count = getCount2(persons);
        System.out.println(count);

        List<Person> persons2 = null;

        persons2.stream().count();
    }


    private static long getCount(List<Person> persons) {
        int count = 0;
        for (Person p : persons) {
            if (p.getAge() > 20) {
                count ++;
            }
        }
        return count;
    }

    private static long getCount2(List<Person> persons) {
        return persons.stream().filter(person -> person.getAge() > 20).count();
    }


}

@Getter
@Setter
class Person {
    int age;

}